<?php

namespace app\admin\controller;

use app\admin\service\PluginService;

class PluginController extends Curd
{
    /**
     * 应用中心
     */
    public function index()
    {
        if (request()->isAjax()) {
            $param = request()->all();
            $pluginService = new PluginService();
            return sparkSuccess($pluginService->getAppList($param));
        }
        return view('plugin/index');
    }
    /**
     * 创建应用
     */
    public function create()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $pluginService = new PluginService();
            return sparkSuccess($pluginService->createPlugin($param));
        }
    }

    /**
     * 卸载插件
     */
    public function uninstall()
    {
        $id = request()->input('id');

        $pluginService = new PluginService();
        return sparkSuccess($pluginService->uninstallPlugin($id));
    }

    /**
     * 安装插件
     */
    public function install()
    {
        $id = request()->input('id');

        $pluginService = new PluginService();
        return sparkSuccess($pluginService->installPlugin($id));
    }

    /**
     * 删除插件
     */
    public function del()
    {
        $id = request()->input('id');
        $pluginService = new PluginService();
        return sparkSuccess($pluginService->deletePlugin($id));
    }

    /**
     * 上传插件
     */
    public function import()
    {
        $param = request()->post();

        $pluginService = new PluginService();
        return sparkSuccess($pluginService->updateOrInstall($param));
    }

    /**
     * 打包
     */
    public function pack()
    {
        $pluginName = request()->input('name');
        $pluginService = new PluginService();
        return sparkSuccess($pluginService->doPack($pluginName));
    }

    /**
     * 制作升级包
     */
    public function updateInfo()
    {
        $param = request()->post();
        $pluginService = new PluginService();
        return sparkSuccess($pluginService->makeUpdateZip($param));
    }
}